#ifndef __SPLINE_HPP__
#define __SPLINE_HPP__

#include <vector>
#include "macros.hpp"

// para output del string del poliniomio
#include <iostream>

class Spline
{

public:
	struct Point {
		double x, y;
		Point(){}
		Point(double _x, double _y):x(_x),y(_y){}
	};

	Spline( const std::vector<Point>& control_points );
	~Spline();

	std::vector<Point> controlPoints() const;

	double operator() ( double x ) const;

	double derivative( double x ) const;
	double derivative2( double x ) const;

	std::ostream& polynomial( std::ostream& out, uint k, char var ) const;

	// funciones para evaluar cada polinomio individualmente
	double eval( double x, uint i ) const;
	double derivative( double x, uint i ) const;
	double derivative2( double x, uint i ) const;

	// devuelve el índice del polinomio para el x dado
	uint findPol( double x ) const;

private:
	void calc();

	std::vector<Point> _cp;
	double* _a;
	double* _b;
	double* _c;
	double* _d;

	uint n;

};


std::ostream& operator<<( std::ostream& out, const Spline& s );

#endif

